<?php
  require_once '../../Helpers/DbHelper.php';
  require_once '../../Controllers/AdminController.php';
  require_once '../../Controllers/UserController.php';
  require_once '../../Helpers/PathHelper.php';
  //
  $u = new UserController();
  $u->evaluatePagePermission(UserController::ADMINISTRATOR);
  //
  $a = new AdminController();
  $departmentList = $a->getDepartmentList();
  $yearLevelList = $a->getYearLevel();
  //
  $fid = $_GET['fid'];

  if(!empty($_POST))
  {
    $feeName = $_POST['fee-desc'];
    $yearId = $_POST['year'];
    $feeAmount = $_POST['fee-amount'];

    $a->updateFees($fid,$feeName,$feeAmount,$yearId);
  }
  if($fid)
  {
    $fees = mysql_fetch_assoc($a->getFees($fid));
    $feeName = $fees['FeeName'];
    $yearId = $fees['YearLevelId'];
    $feeAmount = $fees['FeeAmount'];

  }
  else
  {
    header('Location: fees.php');
  }
?>
<html>
  <head>
    <title>School Enrollment :: School Fees</title>
    <?php
      require_once '../commons.php';
      renderHeaderStyles() ;
    ?>
    </head>
  <div class="container">
    <?php renderAdminNav(); ?>
    <h1>Edit Fees</h1>
    <form name="fees-form" method="post">
      <table align="center" class="labels">
        <tr>
          <td><label for="fee-desc">Fee Description:</label></td>
          <td><input type="text" name="fee-desc" value="<?php echo $feeName; ?>"/></td>
        </tr>
        <tr>
          <td><label for="year-level">Choose a year level: </label></td>
          <td><select name="year">
            <?php
              if(mysql_num_rows($yearLevelList) < 1)
                echo "<option value='0'>No data available</option>";

              while($rows=mysql_fetch_assoc($yearLevelList))
              {
                $i = $rows['YearLevelId'];
                $n = $rows['YearLevelDescription'];

                $content = "<option value='$i'";
                 if($i == $yearId )
                    $content.=" selected";

                $content.=">$n</option>";
                echo $content;
              }
            ?>
            </select></td>
        </tr>
        <tr>
          <td><label for="fee-amount">Fee Amount (PHP):</label></td>
          <td><input type="text" name="fee-amount" value="<?php echo $feeAmount; ?>" /></td>
        </tr>
        <tr><td><input type="submit" name="update-fees" value="Update Fees" /></td></tr>
      </table>
    </form>
    <hr />
    <a href="<?php echo PathHelper::getBaseUrl()?>/Views/Admin/fees.php" id="prev-next">&larr;&nbsp;Back</a>
  </div>
</html>